#ifndef UPG_FACTORY_H
#define UPG_FACTORY_H

#include "upgstruct.h"
#include "ComStruct.h"

class CUpgFactory
{
public:
	CUpgFactory();
	~CUpgFactory();

public:
	// Receive
	SNetVersion* analyDataDatagramVersion(SUpgHead* pUpgHead, char* pData, int iLen);
	int analyDataDatagramStack(SUpgHead* pUpgHead,  CBattStack* pBattStack, char* pData, int iLen); 
	int analyDataDatagramBank(SUpgHead* pUpgHead, CBattBank* pBattBank, CBankAlarm* pBankAlarm, char* pData, int iLen); 
	int prepareExcepDatagram(char* pDataBuf, SHeartbeat* pHeartbeat, SUpgHead* pGPRSHead, int iErrCode);

	// Send
	int prepareDatagramNotify(SHeartbeat* pHeartbeat, const QString& strUpdateInfo, char* pDataBuf);
	int prepareDatagramStack(SHeartbeat* pHeartbeat, CBattStack* pBattStack, char* pDataBuf);
	int prepareDatagramBank(SHeartbeat* pHeartbeat, quint8 uCmdType, CBattBank* pBattBank, CBankAlarm* pBattAlarm, char* pDataBuf, quint8 uModbusAddr);
//	int prepareDatagramBAComInputReg(SHeartbeat* pHeartbeat, quint16* pComInputRegData, char* pDataBuf);
	int prepareDatagramVersion(SHeartbeat* pHeartbeat, CBattStack* pBattStack, char* pDataBuf);
	int prepareDatagramCmd(quint16 usAreaCode, quint8  uStationNo, quint8  uTransmitNo, quint8 uCmdType, CBattBank* pBattBank, char* pDataBuf, quint8 uModbusAddr, const QString& strParam);	

	int addParam2Buffer(char* pData, quint32 uiParamVal);
	int addParam2Buffer(char* pData, quint16 uiParamVal);
	int addParam2Buffer(char* pData, float fParamVal);

	int addCRC2Buffer(uchar *pData, int iLen);

	quint16 CRC16(uchar *pData, quint16 usLen);
	int getParamFromBuffer(char* pData, quint16& uiParamVal);

private:		
	int getParamFromBuffer(char* pData, quint32& uiParamVal);
	int getParamFromBuffer(char* pData, float& fParamVal);	
};

#endif // UPG_FACTORY_H
